package dlg.code.state.context.service.impl;

import dlg.code.state.context.service.AbstractOrderStateService;
import dlg.code.state.domain.OrderInfo;
import dlg.code.state.enums.OrderStateEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UnpaidOrderStateService extends AbstractOrderStateService {
    private final static Logger log = LoggerFactory.getLogger(UnpaidOrderStateService.class);

    public UnpaidOrderStateService() {
        orderStateEnum = OrderStateEnum.UNPAID;
    }

    @Override
    public boolean pay(OrderInfo orderInfo) {
        log.info("订单 {} 执行pay操作", orderInfo.getId());
        changeState(orderInfo, OrderStateEnum.PAID);
        return true;
    }

    @Override
    public void changeState(OrderInfo orderInfo, OrderStateEnum orderStateEnum) {
        log.info("订单 {} 由状态 {} 转为 {}", orderInfo.getId(), orderInfo.getOrderStateEnum().getName(), orderStateEnum.getName());
        orderInfo.setOrderStateEnum(orderStateEnum);
    }
}
